package org.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.example.service.client.HelloClient;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * @author xw
 * @date 2021/6/27 6:46 下午
 */
public class DubboClientBoostrap {
    public static void main(String[] args) throws IOException {
        final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        // ...
        while (true){
            System.in.read();
            new Thread(new Runnable() {
                public void run() {
                    for (int i = 0; i < 10000; i++) {
                        try {
                            Thread.sleep(30);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        new Thread(new Runnable() {
                            public void run() {
                                context.getBean(HelloClient.class).sayHello1();
                            }
                        }).start();
                    }
                }
            }).start();

            new Thread(new Runnable() {
                public void run() {
                    for (int i = 0; i < 10000; i++) {
                        try {
                            Thread.sleep(30);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        new Thread(new Runnable() {
                            public void run() {
                                context.getBean(HelloClient.class).sayHello2();
                            }
                        }).start();
                    }
                }
            }).start();

            new Thread(new Runnable() {
                public void run() {
                    for (int i = 0; i < 10000; i++) {
                        try {
                            Thread.sleep(30);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        new Thread(new Runnable() {
                            public void run() {
                                context.getBean(HelloClient.class).sayHello3();
                            }
                        }).start();
                    }
                }
            }).start();

        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "org.example.service.client")
    @EnableDubbo
    static class ConsumerConfiguration{

    }
}
